package xin.marcher.module.lifecycle.api.impl;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import xin.marcher.module.common.core.JsonResult;
import xin.marcher.module.common.exception.ProductBizException;
import xin.marcher.module.lifecycle.api.ProductExpriDataResultApi;
import xin.marcher.module.lifecycle.domain.request.ProductExpriDataResultRequest;
import xin.marcher.module.lifecycle.service.ProductExpriDataResultService;

/**
 *
 */
@Slf4j
@DubboService(version = "1.0.0", interfaceClass = ProductExpriDataResultApi.class, retries = 0)
public class ProductExpriDataResultApiImpl implements ProductExpriDataResultApi {

    @Autowired
    private ProductExpriDataResultService productExpriDataResultService;

    /**
     * 新增考核指标数据
     *
     * @param request
     * @return
     */
    @Override
    public JsonResult<Long> saveProductExpriDataResult(ProductExpriDataResultRequest request) {
        try {
            Long id = productExpriDataResultService.saveProductExpriDataResult(request);
            return JsonResult.buildSuccess(id);
        } catch (ProductBizException e) {
            log.error("biz error: request={}", request, e);
            return JsonResult.buildError(e.getErrorCode(), e.getErrorMsg());
        } catch (Exception e) {
            log.error("system error: request={}", request, e);
            return JsonResult.buildError(e.getMessage());
        }
    }
}
